package com.onesports.intelligent.k12.polarlight.controller.operation;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.common.IdDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.index.HomeDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.operation.PageOperationHomeDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.operation.PageOperationMessageVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.report.OperationHomePageVO;
import com.onesports.intelligent.k12.polarlight.enums.MessageTypeEnum;
import com.onesports.intelligent.k12.polarlight.service.index.OperationHomePageService;
import com.onesports.intelligent.k12.polarlight.service.operation.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wangcx
 */
@RequiredArgsConstructor
@RestController
@RequestMapping(ApiPathConstants.OPERATION_HOME)
@Api(tags = "运营端-首页")
@PreAuthorize("isAuthenticated()")
public class OperationHomeController {

    private final MessageService service;
    private final OperationHomePageService operationHomePageService;

    @GetMapping("/page")
    @ApiOperation("获取消息通知")
    public ResponseEntity<IPage<PageOperationMessageVO>> page(PageOperationHomeDTO dto){
        List<String> meTypes = new ArrayList<>();
        meTypes.add(MessageTypeEnum.CAMPUS_APPLY.getValue());
        meTypes.add(MessageTypeEnum.COACH_APPLY.getValue());
        dto.setMsgTypes(meTypes);
        return ResultUtil.success(this.service.page(new Page<>(dto.getPage(), dto.getRow()),dto));
    }

    @PostMapping("/del")
    @ApiOperation("删除消息通知")
    public ResponseEntity<String> page(@Valid @RequestBody IdDTO dto){
        this.service.del(dto.getId());
        return ResultUtil.success("删除成功");
    }

    @PostMapping("/read")
    @ApiOperation("标记消息已读")
    public ResponseEntity<String> read(@Valid @RequestBody IdDTO dto){
        this.service.read(dto.getId());
        return ResultUtil.success("标为已读");
    }


    @GetMapping("/read-all")
    @ApiOperation("标记所有消息已读")
    public ResponseEntity<String> readAll(){
        List<String> meTypes = new ArrayList<>();
        meTypes.add(MessageTypeEnum.CAMPUS_APPLY.getValue());
        meTypes.add(MessageTypeEnum.COACH_APPLY.getValue());
        this.service.readAll(meTypes,null);
        return ResultUtil.success("标记成功");
    }

    @ApiOperation("运营简报")
    @PostMapping("briefing")
    public ResponseEntity<OperationHomePageVO> getDetail(@RequestBody @Valid HomeDTO dto){
        return ResultUtil.success(operationHomePageService.getList(dto));
    }
}
